< previous page page_103 next page >

Page 103
Finally, add a single line of code to the Default command button to execute the SetColors procedure.
Sub cmdDefault_Click ()
   SetColors 0
End Sub
Save and run the project. You'll now see that the background for the form and the data control are set to light gray when you click the Default button. The form now meets the default color standards for Win95 forms.
Custom Colors
You may want to set your own customized colors for your form. The following code will do just that. Suppose you want the background to appear in red and the text to appear in blue.
First, add the constants for blue and red to your declaration section:
Option Explicit
'
' constant for colors
Const LIGHT_GRAY = &HC0C0C0
Const WHITE = &HFFFFFF
Const BLACK = &H0
Const BLUE = &H800000
Const RED = &H80
Next, modify the SetColors procedure to include your new colors. Notice that you now need to set both the ForeColor and the BackColor properties of all the controls along with the BackColor of the form itself. This time, you'll set the colors to the custom set if the parameter is set to 1. Here's the code:
Sub SetColors (nSet As Integer)
   '
   ' set to default colors
   If nSet = 0 Then
      pnlDisplayOnly.BackColor = LIGHT_GRAY
      pnlPalette.BackColor = LIGHT_GRAY
      frmColor.BackColor = LIGHT_GRAY
      Data1.BackColor = LIGHT_GRAY
      '
      txtOneLine.BackColor = WHITE
      txtOneLine.ForeColor = BLACK
   End If
   '
   ' set to custom colors
   If nSet = 1 Then
      pnlDisplayOnly.BackColor = RED
      pnlPalette.BackColor = RED
      frmColor.BackColor = RED
      Data1.BackColor = RED
      '

 
< previous page page_103 next page >

If you like this book, buy it!